﻿Public Class SOPExplorer
    Inherits ExplorerTreeList

    Private aPL As PLBase
    Private aDocGen As DocGen

    Public Sub New(ByVal aQueryName As String)
        MyBase.New(aQueryName)
        'AddHandler InitTreeActionOptionList, AddressOf Init_TreeActionOptionList
    End Sub

    Public Sub New()
        MyBase.New()
        'AddHandler InitTreeActionOptionList, AddressOf Init_TreeActionOptionList
    End Sub

    Public Overrides Sub PopulateDetailSection()
        Me.Cursor = Cursors.WaitCursor
        '
        If aGridControl IsNot Nothing Then
            aGridControl.Dispose()
            aGridControl = Nothing
        End If

        Dim frmCaption As String = String.Empty
        Dim DescriptionLang As String = "_PRM"

        Dim guidEnfant As Guid = DirectCast(NodeDataRow(Me.KeyFieldName), Guid)
        Dim aMQ = MetaQuery.GetMetaQueryByName(NodeDataRow("MetaQuerie").ToString)
        aPL = PLBase.CreateInstanceOf(NodeDataRow("PL").ToString(), aMQ.QueryName)

        If Not guidEnfant.Equals(Guid.Empty) Then
            aPL.SQLWhere = String.Format("{0} = '{1}'", aMQ.GUIDField, guidEnfant)
        End If

        If AppManager.ApplicationOption.DescriptionColumnIndex = 3 Then
            DescriptionLang = "_ALT"
        Else
            DescriptionLang = "_PRM"
        End If

        If NodeDataRow.Table.Columns.Contains("Description" & DescriptionLang) Then
            frmCaption = NodeDataRow("Description" & DescriptionLang)
        Else
            frmCaption = "Description" & DescriptionLang
        End If




        aGridControl = New GridExtPL() With {.Dock = DockStyle.Fill, .Pl = aPL, .SecureGrid = True, .Name = aMQ.Caption, .FormCtrlCD = MyBase.PanelName}
        Select Case aMQ.QueryName
            Case "SOPAttribute"
                aGridControl.GridActionOptionList.Add(New ActionOption("Attribute", "ACT_00181", "Edit Document", AddressOf EditDocument, True, True, "SOPAttribute"))
                aGridControl.GridActionOptionList.Add(New ActionOption("Attribute", "ACT_00183", "Edit Grahique", AddressOf EditGraphique, True, True, "SOPAttribute"))

        End Select
        Select Case FocusedNodeLevel
            Case 0
                AddHandler aGridControl.InitNewMasterRow, AddressOf InitNewMasterRow
            Case Else
                AddHandler aGridControl.InitNewMasterRow, AddressOf InitNewMasterRow
        End Select

        '
        'On trouve la form pour effacer les controle dedans et ensuite remettre le bon.
        'Comme ca on change le Detail selon la ligne dans L'explorer
        For Each aFrm As XtraForm In Me.ParentForm.MdiChildren
            If aFrm.Name = PanelName Then
                aFrm.Controls.Clear()
                aFrm.Controls.Add(aGridControl)
                aFrm.Text = frmCaption
                aFrm.Show()
                aFrm.Focus()
            End If
            aFrm.Refresh()
        Next

        Me.Cursor = Cursors.Default

    End Sub

    Private Sub SOPExplorer_Load(sender As Object, e As EventArgs) Handles Me.Load
        TreeActionOptionListLoad()
        MetaControlTreeListActionOptionList.ApplySecurity()
    End Sub

End Class